package code1.binary_tree;

/**
 * 原题链接：https://leetcode.cn/problems/convert-sorted-array-to-binary-search-tree/
 */
public class P108 {


    public TreeNode buildBST(int[] nums,int begin,int end){
        if(begin>end){
            return null;
        }
        int mid=begin+end>>1;
        TreeNode node=new TreeNode(nums[mid]);
        node.left=buildBST(nums,begin,mid-1);       //构建左子树
        node.right=buildBST(nums,mid+1,end);       //构建右子树
        return node;
    }


    public TreeNode sortedArrayToBST(int[] nums) {
        return buildBST(nums,0,nums.length-1);
    }
}
